package hibernatelogic;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;

import orm.Roles;
import utils.HibernateUtil;

/**
 * 
 * The DAO class for table ROLES
 * @author Igor Petrov
 *
 */
public class HibRoles {
	
	public HibRoles(){}
	
	/**
	 * select * from roles;
	 * @throws SQLException
	 */
	public Collection getAllRoles() throws SQLException{
		Session session = null;
	    List roles = new ArrayList<Roles>();
	    try {
	      session = hibUtil.getSessionFactory().openSession();
	      roles = session.createCriteria(Roles.class).list();
	    } catch (Exception e) {
	    	loggerHibRoles.error("getAllRoles failed!!!", e);
	    } finally {
	      if (session != null && session.isOpen()) {
	        session.close();
	      }
	    }
	    return roles;
	}
	
	HibernateUtil hibUtil = new HibernateUtil();
	private static final Logger loggerHibRoles = Logger.getLogger(HibRoles.class); 
}
